/*
 *  Copyright (c) 2010, Baturu.COM. All rights reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.sitevelocity.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * sitevelocity configuration.
 *
 * @author javafuns
 */
public class SiteVelocityConfiguration {
    public final static String MAPPED_ROUTE_IN_REQUEST = "mapped.route.in.request";
    private final static SiteVelocityConfiguration instance = new SiteVelocityConfiguration();
    private Properties resource;

    private SiteVelocityConfiguration() {
        resource = new Properties();
        InputStream in = SiteVelocityConfiguration.class.getClassLoader().getResourceAsStream("/sitevelocity.properties");
        if (in != null) {
            try {
                resource.load(in);
            } catch (IOException ex) {
                SiteVelocityLogger.getLogger(SiteVelocityConfiguration.class.getName()).logError("Failed to read sitevelocity.properties", ex);
            }
        }
    }

    public static SiteVelocityConfiguration getInstance() {
        return instance;
    }

    public String getDefaultIndexPage() {
        return resource.getProperty("default.index.page", "index.vm");
    }

    public String getTemplateExtension() {
        return resource.getProperty("template.extension", ".vm");
    }

    public String getActionExtension() {
        return resource.getProperty("action.extension", ".do");
    }

    public String getViewPackage() {
        return resource.getProperty("view.package", "org.sitevelocity.web.views");
    }

    public String getActionPackage() {
        return resource.getProperty("action.package", "org.sitevelocity.web.actions");
    }

    public String getDateFromat() {
        return resource.getProperty("default.date.format", "yyyy-MM-dd hh:mm:ss");
    }

    public String getProperty(String key) {
        return resource.getProperty(key);
    }
}
